window.workFlowTreeList = {}
window.workFlowTree = {}
window.node_index = 0;

function initAddNodeBox() {
	//下面使用模板字符串，后面
	str =
		`
	<div id="ddfdfdd"  style="display:none;z-index:999;height:100px;width:100px" class="add-node-btn">
	    <el-popover placement="right-start" id>
	        <div class="add-node-popover-body">
	            <a class="add-node-popover-item approver" onclick="addType_1212(1)">
	                <div class="item-wrapper">
	                    <span class="iconfont"></span>
	                </div>
	                <p>审批人</p>
	            </a>
	            <a class="add-node-popover-item notifier" onclick="addType_1212(2)">
	                <div class="item-wrapper">
	                    <span class="iconfont"></span>
	                </div>
	                <p>抄送人</p>
	            </a>
	            <a class="add-node-popover-item condition" onclick="addType_1212(4)">
	                <div class="item-wrapper">
	                    <span class="iconfont"></span>
	                </div>
	                <p>条件分支</p>
	            </a>
	        </div>
			  <button class="btn" type="button" style="background:#eee" slot="reference" onclick="closetttt()">
			   关闭
			                    <span class="iconfont"></span>
			                </button>
	       
	    </el-popover>
	`
	window["addType_1212"] = function(num) {
		return;
	}
	window["closetttt"] = function() {
		$("#ddfdfdd").css("display", "none");
	}
	return str;
}

function showAddNodeBox(nextNode, func) {

	window["addType_1212"] = function(type) {
		if (type != 4) {
			var data;
			if (type == 1) {
				data = {
					"nodeName": "审核人",
					"error": true,
					"type": 1,
					"settype": 1,
					"selectMode": 0,
					"selectRange": 0,
					"directorLevel": 1,
					"replaceByUp": 0,
					"examineMode": 1,
					"noHanderAction": 1,
					"examineEndDirectorLevel": 0,
					"childNode": nextNode,
					"nodeUserList": []
				}
			} else if (type == 2) {
				data = {
					"nodeName": "抄送人",
					"type": 2,
					"ccSelfSelectFlag": 1,
					"childNode": this.childNodeP,
					"nodeUserList": []
				}
			}

			func(data);
		} else {
			data = {
				"nodeName": "路由",
				"type": 4,
				"childNode": null,
				"conditionNodes": [{
					"nodeName": "条件1",
					"error": true,
					"type": 3,
					"priorityLevel": 1,
					"conditionList": [],
					"nodeUserList": [],
					"childNode": this.childNodeP,
				}, {
					"nodeName": "条件2",
					"type": 3,
					"priorityLevel": 2,
					"conditionList": [],
					"nodeUserList": [],
					"childNode": null
				}]
			}
			func(data);
		}


		$("#ddfdfdd").css("display", "none");
		return;
	}
	$("#ddfdfdd").css("display", "block");
}

function click$1(func) {
	if (!func) {
		func = function() {}
	}
	return function(ele, index_x) {
		var titleE = ele.querySelector("[ref='" + index_x + "_title']");
		var contentE = ele.querySelector("[ref='" + index_x + "_content']");
		func.apply({
			ele,
			titleE: titleE,
			contentE: contentE,
			index_x
		}, []);
	}
}
function getANewSPRNode(title,content,clickNodeFunc,clickAddNodeFunc){
	window.node_index ++;
	var str=`
	<div class="node-wrap">
		<div  class="node-wrap-box" onclick="_${window.node_index }_nodeClick(this,${window.node_index })">
			<div>
				<div class="title" style="background: rgb(255, 148, 62);"><span class="iconfont"></span>
					<span class="editable-title" ref='${window.node_index }_title' >${title}</span>
					<i class="anticon anticon-close close" onclick="delitem(${window.node_index })"></i></div>
				<div class="content">
					<!---->
					<div  class="text" ref='${window.node_index }_content'>
						${content}
					</div>
					<i class="anticon anticon-right arrow"></i>
				</div>
			
			</div>
		</div>
		
		
		<div class="add-node-btn-box" style="height: 160px;" >
				<div class="add-node-btn">
				<span style="top: 48px;left: 105px;position: absolute;">
				<button onclick="_addClick(this,${window.node_index })" type="button" style="padding:0"  class="btn el-popover__reference" aria-describedby="el-popover-3642" tabindex="0"><span
					 class="iconfont"></span></button>
					<div ref="_${window.node_index }_tool_trip"  role="tooltip" aria-hidden="false" class="el-popover el-popper" tabindex="0" style="z-index: 2008;
					position: relative;top: -70px;left: 60px;display:none">
						<div class="add-node-popover-body">
						   <a onclick="_addShenPiren(${window.node_index })" class="add-node-popover-item approver">
								<div class="item-wrapper"><span class="iconfont"></span>
								
								</div>
								<p>审批人</p>
							</a>
							<a onclick="_addChaosongren(${window.node_index })" class="add-node-popover-item notifier">
								<div class="item-wrapper"><span class="iconfont"></span></div>
								<p>抄送人</p>
							</a><a onclick="_addtianjian(${window.node_index })" class="add-node-popover-item condition">
								<div class="item-wrapper"><span class="iconfont"></span></div>
								<p>条件分支</p>
							</a></div>
						
					</div>
					
					
					
					
				</span>
			</div>
		</div>
	</div>
	
	`
	return str
}

function getAnewCSRNode(title,content,clickNodeFunc,clickAddNodeFunc){
	window.node_index ++;
	var ss=`
	<div class="node-wrap">
		<div class="node-wrap-box">
			<div>
				<div class="title" style="background: rgb(50, 150, 250);"><span class="iconfont" style="display: none;"></span><span
					 class="iconfont" style=""></span>
					<span class="editable-title" ref='${window.node_index }_title' >${title}</span>
					<i class="anticon anticon-close close" onclick="delitem(${window.node_index })"></i></div>
				<div class="content">
					
					<div class="text" ref='${window.node_index }_content'>
						${content}
						
					</div><i class="anticon anticon-right arrow"></i>
				</div>
				
			</div>
		</div>
	
	
	
	</div>
	`
	return ss;
	
}


function delitem(index){
	window.node_index--;
	$("#app .node-wrap")[index].remove();
}

function _addClick(ele,index){
	$("[ref='_"+index+"_tool_trip']").css("display","block");
	return false;
}
function _addShenPiren(index){
	// document.querySelector("[ref='_"+index+"_tool_trip']").style.display='none';
	var str=getANewSPRNode("审批人","ddd");
	$(str).insertAfter($("#app .node-wrap")[index]);
	$("[ref='_"+index+"_tool_trip']").hide();
	return false;
}
function _addChaosongren(index){
	var str=getAnewCSRNode("抄送人","季文飞");
	$(str).insertAfter($("#app .node-wrap")[index])
	$("[ ref='_"+index+"_tool_trip']").css("display","none")
	return false;
}
function getFirstNode(title, content, clickNodeFunc, clickAddNodeFunc) {
	window._0_nodeClick = click$1(clickNodeFunc);
	return `
	<div class="node-wrap">
		<div class="node-wrap-box start-node " onclick="_0_nodeClick(this,0)">
			<div>
				<div class="title" style="background: rgb(87, 106, 149);">
					<span class="iconfont" style="display: none;"></span>
					<span class="iconfont" style="display: none;"></span>
					<span ref='0_title'>${title}</span>
					
				</div>
				<div class="content">
					<div class="text" ref='0_content'>${content}</div>
					<i class="anticon anticon-right arrow"></i>
				</div>
			</div>
		</div>
		<div class="add-node-btn-box" style="height: 160px;" >
			<div class="add-node-btn">
			<span style="top: 48px;left: 105px;position: absolute;">
			<button onclick="_addClick(this,0)" type="button" style="padding:0"  class="btn el-popover__reference" aria-describedby="el-popover-3642" tabindex="0"><span
				 class="iconfont"></span></button>
				<div ref="_0_tool_trip"  role="tooltip" aria-hidden="false" class="el-popover el-popper" tabindex="0" style="z-index: 2008;
				position: relative;top: -70px;left: 60px;display:none">
					<div class="add-node-popover-body">
					   <a onclick="_addShenPiren(0)" class="add-node-popover-item approver">
							<div class="item-wrapper"><span class="iconfont"></span>
							
							</div>
							<p>审批人</p>
						</a>
						<a onclick="_addChaosongren(0)" class="add-node-popover-item notifier">
							<div class="item-wrapper"><span class="iconfont"></span></div>
							<p>抄送人</p>
						</a><a onclick="_addtianjian(0)" class="add-node-popover-item condition">
							<div class="item-wrapper"><span class="iconfont"></span></div>
							<p>条件分支</p>
						</a></div>
					
				</div>
				
				
				
				
			</span>
		</div>
	</div>
	</div>
	`
}
var Faqiren=(function($){
	var faqirenReulst={}
	 function init(faqirenFunc,sureFaqirenFunc,cancelFaqirenFunc) {
		str =
			`
			<div ref="FaqirenBox" style="display:none;z-index:999" class="el-drawer__container el-drawer__open">
		<div  aria-modal="true" aria-labelledby="el-drawer__title" role="presentation" class="el-drawer rtl" style="width: 550px;">
			<header id="el-drawer__title" class="el-drawer__header"><span role="heading">发起人</span><button aria-label="close 发起人"
				 type="button" class="el-drawer__close-btn"><i class="el-dialog__close el-icon el-icon-close"></i></button></header>
			<section class="el-drawer__body">
				<div class="demo-drawer__content">
					<div class="promoter_content drawer_content" >
						<p ref="faqirent" ></p>

					</div>
					<button type="button" class="el-button el-button--primary" onclick="_addFaqiren()">
						<span>添加/修改发起人</span>
					</button>
					<div class="demo-drawer__footer clear"><button type="button" class="el-button el-button--primary" onclick="_sureFaqiren()">
						<span>确 定</span></button>
						
						<button type="button" class="el-button el-button--default" onclick="_cancelFaqiren()">
							<span>取 消</span></button></div>
				</div>
			</section>
		</div>
		</div>
		`;
		window._addFaqiren=function(){
		
			var faqirentxtBox = document.querySelector("[ref='FaqirenBox']").querySelector('[ref="faqirent"]');
			
			faqirenReulst=faqirenFunc.apply({faqirentxtBox},[]);
			return false;
		}
		window._sureFaqiren=function(){
			$("[ref='FaqirenBox']").css("display","none")
			if(!!sureFaqirenFunc)sureFaqirenFunc(faqirenReulst);
			
		}
		window._cancelFaqiren=function(){
			$("[ref='FaqirenBox']").css("display","none")
			if(!!cancelFaqirenFunc)cancelFaqirenFunc();
		}
		return str;
	}
	function show(data){
		var box=$("[ref='FaqirenBox']")
		box.css("display","block")
		box.find("[ref='faqirent']").html(data)
	}
	return {
		init,
		show
	};
})($);





